﻿local function CastSpell(strSpell)
	RunMacroText("/run CastSpellByName(\""..strSpell.."\");");
end

local function MyCastSpell(strSpell)
	RunMacroText("/cast "..strSpell);
end

local function GetMyDebuffTime(p_Unit, p_BuffName) --获取目标上我释放的Debuff的剩余时间
	local i=1;
	repeat
		local BuffName,_,_,_,_,_,timeLeft,castBy=UnitDebuff(p_Unit,i);
		if(BuffName == p_BuffName and castBy == "player")then
			if(time == 0)then
				return 0;
			else 
				return timeLeft-GetTime();
			end
		end
		i = i + 1;
	until BuffName==nil
	return -1;
end

local function GetSkillCD(p_SkillName) --获取技能CD时间
	local timeLeft,timeRight = GetSpellCooldown(p_SkillName);
	if(timeLeft~=nil and timeLeft>0)then
		return timeLeft+timeRight-GetTime();
	else
		return 0;
	end
end

local function GetBuffTime(p_BuffName)	--获取Buff剩余时间
	local _,_,_,_,_,_,time=UnitBuff("player",p_BuffName);
	if(time == nil)then
		return -1;
	elseif(time == 0)then
		return 0;
	else
		return time-GetTime();
	end
end

local function GetBuffCount(p_BuffName)	--获取技能层数
	local _,_,_,count=UnitBuff("player",p_BuffName);
	if (count==nil)then
		return 0;
	elseif(count==0)then
		return 1;
	else
		return count;
	end
end

local timeLastYanJingShe = 0;

function HunterDPS()
	local hp,hpMax, MyMana = UnitHealth("target"), UnitHealthMax("target"), UnitMana("player");
	local DuSheDingCiTime = GetMyDebuffTime("target","毒蛇钉刺");
	local cdShaNu, cdKuangYeNuHuo, cdJiSuSheJi, cdZhunBeiJiuXu, cdFengLuan, cdQunShow= GetSkillCD("杀戮命令"), GetSkillCD("狂野怒火"), GetSkillCD("急速射击"), GetSkillCD("准备就绪"), GetSkillCD("疯乱"), GetSkillCD("群兽奔腾");

	if(hp/hpMax>=0.05 and hp >=100000 and DuSheDingCiTime<0)then	--判断是否放毒蛇
		strCastSpell="毒蛇钉刺";
	elseif(DuSheDingCiTime >= 0 and DuSheDingCiTime<=4 and GetTime()-timeLastYanJingShe>1)then			--判断是否补毒蛇,非补不可的情况
		if(UnitCastingInfo("player")=="眼镜蛇射击")then
			timeLastYanJingShe = GetTime();
		end
		if(MyMana>=105)then
			strCastSpell="毒蛇钉刺";				--判断是否泄集中补毒蛇
		else
			strCastSpell="眼镜蛇射击";
		end
	elseif(cdShaNu<=0.3 and MyMana>=38)then	--判断是否杀戮命令,可以等一会集中和CD
		strCastSpell="杀戮命令";
	elseif(GetSkillCD("杀戮射击")==0 and hp/hpMax<=0.2)then
		SpellStopCasting();
		strCastSpell="杀戮射击";
	elseif(DuSheDingCiTime>=0 and DuSheDingCiTime<=7 and MyMana<45 and GetTime()-timeLastYanJingShe>1)then	--判断是否补毒蛇,集中比较少的情况
		if(UnitCastingInfo("player")=="眼镜蛇射击")then
			timeLastYanJingShe = GetTime();
		end
		strCastSpell="眼镜蛇射击";
	elseif(cdKuangYeNuHuo >= 12 and GetBuffCount("野兽之心")==0 and (GetBuffCount("狂乱") == 5 or (GetBuffTime("狂乱")<=6 and GetBuffCount("狂乱")>=3)))then	--判断狂乱是否到了5层，如果只有3层但是时间快到了也放 集中火力
		strCastSpell="集中火力";
	elseif(MyMana>=56 or (MyMana>=36 and UnitBuff("player","狩猎刺激")))then	--有免费buff就留40击中放奥射,没有就留60击中放奥射
		strCastSpell="奥术射击";
	else
		strCastSpell="眼镜蛇射击";
	end
	--print(strCastSpell);
	CastSpell(strCastSpell);
end

function HunterMaxDPS()
	local hp,hpMax, MyMana = UnitHealth("target"), UnitHealthMax("target"), UnitMana("player");
	local DuSheDingCiTime = GetMyDebuffTime("target","毒蛇钉刺");
	local cdShaNu, cdKuangYeNuHuo, cdJiSuSheJi, cdZhunBeiJiuXu, cdFengLuan, cdQunShow= GetSkillCD("杀戮命令"), GetSkillCD("狂野怒火"), GetSkillCD("急速射击"), GetSkillCD("准备就绪"), GetSkillCD("疯乱"), GetSkillCD("群兽奔腾");

	if(hp/hpMax>=0.05 and hp >=100000 and DuSheDingCiTime<0)then	--判断是否放毒蛇
		strCastSpell="毒蛇钉刺";
	elseif(cdZhunBeiJiuXu == 0 and cdShaNu > 3 and (cdKuangYeNuHuo >= 15 and GetSkillCD("急速射击") >= 50))then	--判断是否放准备就绪
		strCastSpell="准备就绪";
	elseif(cdQunShow == 0 and (cdKuangYeNuHuo==0 or cdKuangYeNuHuo <= 8))then --判断是否开群兽
		strCastSpell="群兽奔腾";
	elseif(cdKuangYeNuHuo==0 and GetBuffCount("野兽之心")==0 and cdShaNu<=0.5)then	--判断是否开红人
		strCastSpell="狂野怒火";
	elseif(cdFengLuan==0 and cdKuangYeNuHuo > 20)then	--判断是否开疯乱
		strCastSpell="疯乱";
	elseif(cdJiSuSheJi==0 and GetBuffCount("急速射击")==0 and MyMana<=100 and GetBuffCount("野兽之心") == 0)then	--判断是否开急速射击
		strCastSpell="急速射击";
	elseif(GetSkillCD("山猫冲锋")==0)then
		strCastSpell="山猫冲锋";
	elseif(DuSheDingCiTime >= 0 and DuSheDingCiTime<=3 and GetTime()-timeLastYanJingShe>1)then			--判断是否补毒蛇,非补不可的情况
		if(UnitCastingInfo("player")=="眼镜蛇射击")then
			timeLastYanJingShe = GetTime();
		end
		if(MyMana>=105)then
			strCastSpell="毒蛇钉刺";				--判断是否泄集中补毒蛇
		else
			strCastSpell="眼镜蛇射击";
		end
	elseif(cdShaNu<=0.3 and MyMana>=38)then	--判断是否杀戮命令,可以等一会集中和CD
		strCastSpell="杀戮命令";
	elseif(GetSkillCD("杀戮射击")==0 and hp/hpMax<=0.2)then
		SpellStopCasting();
		strCastSpell="杀戮射击";
	elseif(DuSheDingCiTime >= 0 and DuSheDingCiTime <= 6 and MyMana<40 and GetTime() - timeLastYanJingShe>1)then	--判断是否补毒蛇,集中比较少的情况
		if(UnitCastingInfo("player")=="眼镜蛇射击")then
			timeLastYanJingShe = GetTime();
		end
		strCastSpell="眼镜蛇射击";
	elseif(cdKuangYeNuHuo >= 12 and GetBuffCount("野兽之心")==0 and (GetBuffCount("狂乱") == 5 or (GetBuffTime("狂乱")<=6 and GetBuffCount("狂乱")>=3)))then	--判断狂乱是否到了5层，如果只有3层但是时间快到了也放 集中火力
		strCastSpell="集中火力";
	elseif(MyMana>=56 or (MyMana>=36 and UnitBuff("player","狩猎刺激")))then	--有免费buff就留40击中放奥射,没有就留60击中放奥射
		strCastSpell="奥术射击";
	else
		strCastSpell="眼镜蛇射击";
	end
	--print(strCastSpell);
	CastSpell(strCastSpell);
end